package com.sproutcat.sample;


import org.apache.commons.lang3.time.StopWatch;

import java.util.concurrent.TimeUnit;

public class StopWatchSample2 {

    public static void main(String[] args) throws InterruptedException {
        StopWatch stopWatch = StopWatch.createStarted();
        Thread.sleep(5000);
        stopWatch.split();
        System.out.println("1 " + stopWatch.getTime() + " ms");

        Thread.sleep(1000);
        stopWatch.split();
        System.out.println("2 " + stopWatch.getTime() + " ms");
        System.out.println("2 " + stopWatch.getSplitTime() + " ms");

        Thread.sleep(2000);
//        stopWatch.split();
        System.out.println("3 " + stopWatch.getTime() + " ms");
        System.out.println("3 " + stopWatch.getSplitTime() + " ms");

        System.out.println("花费的时间》》 " + stopWatch.getTime() + " ms");
        System.out.println("花费的时间》》 " + stopWatch.getTime(TimeUnit.SECONDS) + " s");

        // 重置后必须使用start方法
        stopWatch.reset();
        stopWatch.start();
        Thread.sleep(1000);
        System.out.println("重新开始后到当前运行时间是：" + stopWatch.getTime());

        //暂停
        stopWatch.suspend();
        Thread.sleep(6000);

        //上面suspend，这里要想重新统计，需要恢复一下
        stopWatch.resume();
        System.out.println("恢复后执行的时间是：" + stopWatch.getTime());

        stopWatch.stop();
        System.out.println("花费的时间》》 " + stopWatch.getTime() + " ms");
        System.out.println("花费的时间》》 " + stopWatch.getTime(TimeUnit.SECONDS) + " s");
    }

}
